package com.example.leetdemo.finash;

import lombok.Data;

@Data
public class Solution2013 {
    private int[][] w;
    private int time = 0;
    public Solution2013() {
        this.w = new int[1001][1001];
    }

    public void add(int[] point) {
        w[point[0]][point[1]]++;
    }

    public int count(int[] point) {
        time++;
        int count = 0;
        int x = point[0], y = point[1];
        for (int i = 0 ; i < 1001; i++) {
            if (w[i][y] >= 0) {
                int abs = Math.abs(x - i);
                if (abs == 0) {
                    continue;
                }
                if (y - abs >= 0 && w[i][y - abs] != 0 && w[x][y - abs] != 0) {
                    count += (w[i][y] * w[i][y - abs] * w[x][y - abs]);
                }
                if (y + abs < 1001 && w[i][y + abs] != 0 && w[x][y + abs] != 0) {
                    count += (w[i][y] * w[i][y + abs] * w[x][y + abs]);
                }
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Solution2013 solution2013 = new Solution2013();
        solution2013.add(new int[] {1,1});
        solution2013.add(new int[] {1,2});
        solution2013.add(new int[] {2,1});
        System.err.println(solution2013.count(new int[] {2,2}));
        solution2013.add(new int[] {1,1});
        System.err.println(solution2013.count(new int[] {2,2}));
    }


}
